package seven.test_7_21;

import java.util.Scanner;

public class TestMain1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int t = scanner.nextInt();
        for (int i = 0; i < t; i++) {
            int n = scanner.nextInt();
            int k = scanner.nextInt();
            int count = 0;
            int tmp = 0;
            scanner.nextLine();
            String str = scanner.nextLine();
            for (int  j = 0; j < n; j++) {
                char c = str.charAt(j);
                if (c == 'L') {
                    tmp = 0;
                    count -= 1;
                }
                if (c == 'W') {
                    tmp++;
                    if (tmp >= 3) {
                        count += k;
                    } else {
                        count += 1;
                    }
                }
            }
            System.out.println(count);
        }
    }
}
